﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Net;

namespace SocketDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IPAddress address = IPAddress.Loopback;
            IPEndPoint endPoint = new IPEndPoint(address, 49152);
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind(endPoint);
            socket.Listen(10);
            Console.WriteLine("开始侦听，端口号：{0}",endPoint.Port);
            while (true)
            {
                Socket client = socket.Accept();
                Console.WriteLine(client.RemoteEndPoint);
                byte[] buffer=new byte[4094];
               int length= client.Receive(buffer, 4094, SocketFlags.None);
                System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
                string requeststring = utf8.GetString(buffer, 0, length);
                Console.WriteLine(requeststring);
                string statusLine = "HTTP/1.1 200 OK\r\n";
                byte[] statusLineBytes = utf8.GetBytes(statusLine);
                string responseBody="<html><head><title>From Socket Server</title></"+
                    ""
            }
        }
    }
}
